package com.atguigu.juc.atomics;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author yfstart
 * @create 2022-07-19 23:45
 */
public class PrepareCas {
    volatile int number = 0;

    // 读取
    public int getNumber() {
        return number;
    }

    // 写入加锁保证原子性
    public synchronized void setNumber() {
        number++;
    }

    // =================================

    AtomicInteger atomicInteger = new AtomicInteger();

    public int getAtomicInteger() {
        return atomicInteger.get();
    }

    public void setAtomicInteger() {
        atomicInteger.getAndIncrement();
    }
}
